package com.pets.web.controller.admin;


import com.pets.common.core.controller.BaseController;
import com.pets.common.core.domain.AjaxResult;
import com.pets.common.core.page.TableDataInfo;
import com.pets.common.utils.SecurityUtils;
import com.pets.web.dto.SearchOrderDto;
import com.pets.web.entity.PetsOrders;
import com.pets.web.service.IPetOrdersService;
import com.pets.web.vo.PetOrdersSearchRequest;
import com.pets.web.vo.SearchOrderRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author zhurenwang
 * @since 2024-05-26
 */
@RestController
@RequestMapping("/orders")
public class PetOrdersController extends BaseController {

    @Autowired
    private IPetOrdersService petOrdersService;

    @GetMapping("/list")
    public TableDataInfo<PetsOrders> list(PetOrdersSearchRequest request){
        startPage();
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            request.setSysUserId(null);
        } else {
            request.setSysUserId(SecurityUtils.getUserId());
        }
        List<PetsOrders> list = petOrdersService.list(request);
        return getDataTable(list);
    }

    @GetMapping("/searchOrder")
    public AjaxResult searchOrder(SearchOrderRequest request){
        SearchOrderDto dto = petOrdersService.searchOrder(request);
        return AjaxResult.success(dto);
    }


    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Integer id){
        return success(petOrdersService.deleteById(id));
    }

    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Integer id){
        return success(petOrdersService.getById(id));
    }

    @PutMapping()
    public AjaxResult edit(@RequestBody PetsOrders petsOrders){
        return success(petOrdersService.updateById(petsOrders));
    }


}
